//角色管理

import r from '@/utils/request';
import type { ListParams, ListResponseType ,ResponseType} from '../types';

enum API {
    list = '/role/list', //角色列表
    del = '/role/delete/', //删除角色
    add = '/role/add', //添加/修改角色
    menulist = '/menu/list', //获取所有权限列表
    roleget = '/role/get/' ,//获取单个角色
    delAll='/role/deleteAll'//批量删除
}
export type GetrolelistResType = ListResponseType<{
    id: number;
    name: string;
    companyId: number;
    addAccountId: number;
    addAccountName: string;
    addTime: string;
    accountCounts: number;
    menuIds: null;
}>
type GetroleAddResType = ResponseType<{
    id: number;
    name: string;
    companyId: number;
    addAccountId: number;
    addAccountName: null;
    addTime: string;
    accountCounts: number;
    menuIds: number[];
}>
export interface getRoleAddParams {
    id: number;
    name: string;
    menuIds: number[];
}
type GetmenulistResType = ResponseType<{
    id: number;
    name: string;
    icon: null | string;
    url: null | string;
    pathName: null | string;
    pid: number;
    sort: number;
    type: number;
    isButton: number;
}>
type RolegetResType = ResponseType<{
    id:             number;
    name:           string;
    companyId:      number;
    addAccountId:   number;
    addAccountName: null;
    addTime:        null;
    accountCounts:  number;
    menuIds:        number[];
}>


export interface roleItem {
    id: number;
}

export interface MenuItem {
    id: number;
    name: string;
}

export function getRolelistAPI(params?: ListParams): Promise<GetrolelistResType> {

    return r.get(API.list, params);
}
export function DelRoleAPI(id: number): Promise<ResponseType<null>> {
    return r.delete(API.del+id);
}
export function AddRoleAPI(data: getRoleAddParams): Promise<ResponseType<GetroleAddResType>> {
    return r.post(API.add, data);
}
export function MenulistAPI(): Promise<ListResponseType<GetmenulistResType>> {
    return r.get(API.menulist);
}
export function RolegetAPI(id: number): Promise<RolegetResType> {
    return r.get(API.roleget+id);
}
export function DelAllRoleAPI(id: number[]): Promise<ResponseType<null>> {
    return r.post(API.delAll, id);
}